#include "widget.h"
#include "ui_widget.h"
#include <QIcon>
#include <QDebug>
#include <QKeySequence>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //设置button图标
    QIcon con_target(":/car.png");
    ui->pushButton_target->setIcon(con_target);
    ui->pushButton_target->setIconSize(QSize(100,100));
    ui->pushButton_up->setIcon(QIcon(":/up.png"));
    ui->pushButton_down->setIcon(QIcon(":/down.png"));
    ui->pushButton_left->setIcon(QIcon(":/left.png"));
    ui->pushButton_right->setIcon(QIcon(":/right.png"));
    //设置快捷键关联
    ui->pushButton_up->setShortcut(QKeySequence("w"));
    ui->pushButton_down->setShortcut(QKeySequence("s"));
    ui->pushButton_left->setShortcut(QKeySequence("a"));
    ui->pushButton_right->setShortcut(QKeySequence("d"));
    ui->pushButton_up->setAutoRepeat(true);
    ui->pushButton_down->setAutoRepeat(true);
    ui->pushButton_left->setAutoRepeat(true);
    ui->pushButton_right->setAutoRepeat(true);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_up_clicked()
{
    //先获取当前位置
    const QRect pos = ui->pushButton_target->geometry();
    ui->pushButton_target->setGeometry(pos.x(),pos.y()-5,pos.width(),pos.height());
    qDebug()<<"up!";

}

void Widget::on_pushButton_down_clicked()
{
    //先获取当前位置
    const QRect pos = ui->pushButton_target->geometry();
    ui->pushButton_target->setGeometry(pos.x(),pos.y()+5,pos.width(),pos.height());
    qDebug()<<"down!";
}
//省略...以up为例子即可
